<?php
	defined( '_JEXEC' ) or die( 'Restricted access' );
	jimport('joomla.application.component.view');
	class SocialRoutesViewRouteList extends JView
	{
		var $_option = null;
		
		function display($tpl = null)
		{		
			$option=JRequest::getCmd('option');
			
			$model = &$this->getModel();
			$routes = $model->getRoutes();
			$user= $model->getUser();
			
			//$pageNav=$model->getPagination();
			$this->assignRef('option', $option);
			$this->assignRef('routes', $routes);
			$this->assignRef('user', $user);
			//$this->assignRef('pageNav', $pageNav);
			
			$this->addCSS();
			$this->addRoutesJavascript($routes);
			$this->addJavascripts();
			
			parent::display($tpl);
		}
		
		private function addCSS(){
			$option=JRequest::getCmd('option');
			
			$document=&JFactory::getDocument();
			$document->addStyleSheet('components/'.$option.'/css/black-tie/jquery-ui-1.8.13.custom.css');
		}
		
		private function addRoutesJavascript($routes){
			?>
			<script>
				var routes= new Array();
				<?php
					for ($i = 0, $total = count($routes); $i < $total; $i ++){
						echo "\n routes[".$i."] =".$routes[$i]->getId().";"; 
						echo "\n addRoute({id:'".$routes[$i]->getId()."'})";
					}
				?>
			</script>
			<?php 
		}
		
		private function addJavascripts(){
			$option=JRequest::getCmd('option');
			
			$document = &JFactory::getDocument();
			$document->addScript( 'http://maps.google.com/maps/api/js?sensor=false' );
			$document->addScript( 'components'.DS.$option.DS.'js'.DS.'jquery-1.5.1.min.js' );
			$document->addScript( 'components'.DS.$option.DS.'js'.DS.'jquery-ui-1.8.13.custom.min.js' );
			$document->addScript( 'components'.DS.$option.DS.'js'.DS.'jqSearch.js' );
			$document->addScript( 'components'.DS.$option.DS.'js'.DS.'routeCommons.js' );
			$document->addScript( 'components'.DS.$option.DS.'js'.DS.'userRoutes.js' );
		}
		
		function paintResultRoute($route){
			$this->assignRef('route',$route);
			jimport('joomla.file.path'); 
			include JPath::find($this->_path['template'], 'resultroute.php'); 
		}
		
		function paintMyRoutesTask(){
			$modelRoute=&$this->getModel('SocialRoutesRoute');
			$this->addTemplatePath(JPATH_COMPONENT.DS.'views'.DS.'route'.DS.'tmpl');
			jimport('joomla.file.path'); 
			$this->assignRef('myRoutesTask', $modelRoute->getMyRoutesTask($this->route));
			include JPath::find($this->_path['template'], 'default_myroutetask.php'); 
		}
		function checkIsCreator(){
			$modelRoute=&$this->getModel('SocialRoutesRoute');
			return $modelRoute->getIsCreator($this->route);
		}
		function paintRouteDetails(){
			$this->addTemplatePath(JPATH_COMPONENT.DS.'views'.DS.'route'.DS.'tmpl');
			jimport('joomla.file.path'); 
			include JPath::find($this->_path['template'], 'default_routedetails.php'); 
		}
	}
?>